<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <meta name="renderer" content="webkit"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
    <link rel="stylesheet" href="/assets/ztree/css/metroStyle/metroStyle.css"/>
</head>
<body>

<ui id="permissionTree" class="ztree"></ui>
<script src="/assets/amazeui/js/jquery-3.2.0.min.js"></script>
<script src="/assets/ztree/js/jquery.ztree.all.js"></script>
<script>

    $(function(){
        loadTree();
    });
    
    function loadTree() {
        $.ajax({
            type: 'post',
            url: '/sys/permission/getTree',
            dataType: 'json',
            success: function(result){

                if(result&&result.data){

                    var noteArr = new Array();
                    $.each(result.data,function(index,obj){
                        var node = {};
                        node.id = obj.permissionId;
                        node.pId = obj.parentId;
                        node.name = obj.name;
                        if(obj.usable){
                            node.chkDisabled = false;
                        }else{
                            node.chkDisabled = true;
                        }
                        if(obj.type!=3){
                            node.isParent = true;
                            node.open = true;
                        }else{
                            node.isParent = false;
                        }


                        noteArr[index] = node;
                    });

                    var setting = {
                        view: {
                            selectedMulti: false
                        },
                        check: {
                            enable: true
                        },
                        data: {
                            simpleData: {
                                enable: true
                            }
                        }
                    };
                    $.fn.zTree.init($("#permissionTree"), setting, noteArr);

                }
            }
        });
    }

</script>
</body>
</html>